<template>
  <div>
    <!-- 一条文章单元格 -->
    <van-cell  @click="clickFn">
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ item.title }}</span>
          <img
            class="thumb"
            v-if="item.cover.type === 1"
            v-lazy="item.cover.images[0]"
          />
        </div>
        <div v-if="item.cover.type > 1" class="thumb-box">
          <img
            class="thumb"
            v-for="(imgUrl, index) in item.cover.images"
            :key="index"
            v-lazy="imgUrl"
          />
        </div>
      </template>
      <!-- label 区域的插槽 -->
      <template #label>
        <div class="label-box">
          <div>
            <span>作者:{{ item.aut_name }} &nbsp; &nbsp;</span>
            <span>{{ item.comm_count }}评论 &nbsp; &nbsp;</span>
            <span>{{ item.pubdate }}</span>
          </div>

          <!-- 反馈按钮 -->
          <van-icon name="cross" @click.stop="onShow" v-if="closeShow" />
        </div>
      </template>
    </van-cell>
    <van-action-sheet
      v-model="show"
      :actions="actions"
      :cancel-text="cancelText"
      @select="onSelect"
      get-container="body"
      @cancel="cancelFn"
    />
  </div>

</template>

<script>
import { firstActions, secondsActions } from '@/api/reports'
export default {
  props: {
    item: {
      type: Object, // 传递类型是对象
      default () {
        // 默认类型
        return {}
      }
    },
    closeShow: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {
      show: false,
      actions: firstActions,
      cancelText: '取消'
    }
  },
  methods: {
    // 一级面板点击事件
    onSelect (action, index) {
      console.log(action, index)
      if (action.name === '不感兴趣') {
        this.$emit('removeE', this.item, action)
      } else if (action.name === '反馈垃圾内容') {
        this.actions = secondsActions
        this.cancelText = '返回'
      } else if (action.name === '拉黑作者') {
        // 什么也不做
      } else {
        this.$emit('removeE', this.item, action)
      }
    },
    clickFn () {
      this.$router.push({
        path: `/article/${this.item.art_id}`
      })
    },
    onShow () {
      this.show = true
    },
    // 点击取消按钮时出发
    cancelFn () {
      if (this.cancelText === '返回') {
        this.cancelText = '取消'
        this.show = true
        this.actions = firstActions
      }
      // this.cancelText = '取消'
      // this.actions = firstActions
      // setTimeout(() => {
      //   this.show = true
      // })
    }
  }

}
</script>

<style scoped lang="less">
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
/* 图片的样式, 矩形黄金比例：0.618 */
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
